<?php require ("header.php"); ?>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
.style1 {color: #000000}
.style2 {
	color: #FFFFFF;
	font-weight: bold;
}
-->
</style>
<?php
	include ("../config/conn.php");
	if ($ad_check<1){
			header ("Location:../login.php?action=0");
	}
?>

<?php
	//setting appropriate variable.
	$up_folder="";
	
	//setting all SQL statement
	$sql_get_dep="SELECT * FROM admin WHERE ad_no='$id'";
	$get_dep=mysql_query($sql_get_dep);
	$dep=mysql_fetch_assoc($get_dep);
	$ad_dep=$dep['ad_department'];
	$sql_get_note="SELECT * FROM notes WHERE note_department='$ad_dep' ORDER BY note_subject ASC";
	$get_note=mysql_query($sql_get_note);
	$num_row=mysql_num_rows($get_note);
?>

<?php
	//setting page limit and pagination variable
	$limit=20;
	if (isset($_GET['id'])){
		$data=$_GET['id'];
	} else {
		$data=0;
	}
	$total_page=intval($num_row/$limit);
	$temp = $num_row-($total_page*$limit);
	if ($temp > 0 ) { 
		$total_page++;
	}
	if ($data>$num_row) {
		echo "<center>cannot process your request.  Your request exceed the amount of data in database.</center>";
		exit();
	}
	//get current page
	$current=intval(($data+$limit)/$limit);
	
	//set the previous and next link to be valid or not.
	if ($data<1) {
		$previous=0; // previous link is invalid
	} else {
		$previous=1; // previous link is valid
	}
	if (($num_row-$data)<=$limit) {
		$next=0;  // next link is invalid
	} else {
		$next=1;  // next link is valid
	}	
?>
<br><table width="780" border="0" align="center">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><div align="center"><a href="note_reg.php">Register New Notes</a></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table><br>
<table width="780" height="24" border="0" align="center">
  <tr>
    <td width="193" height="20"><span class="style1">List result <?php echo $data+1; ?> - 
      <?php 
		if (($num_row < $limit) || (($num_row-$data)<$limit)) { 
			echo $num_row; 
		} else { 
			echo ($data+$limit); 
		} 
	?> 
    </span></td>
    <td width="188"><span class="style1"></span></td>
    <td width="94"><span class="style1"></span></td>
    <td width="287"><div align="right" class="style1">
		<?php if ($previous==1) {
			echo "<a href=\"page.php?id=" .($data-$limit)."\">Previous</a>";
		} else { ?>Previous<?php } ?>
		 | Page <?php echo $current; ?> | 
	<?php if ($next==1) {
			echo "<a href=\"page.php?id=" .($data+$limit)."\">Next</a>";
		} else { ?>Next<?php } ?> </div></td>
  </tr>
</table>

<table width="780" border="1" align="center" bordercolor="#000000" bgcolor="#000000">
  <tr>
    <td width="56" bgcolor="#666666"><div align="center"><strong>Subject</strong></div></td>
    <td width="220" bgcolor="#666666"><div align="center"><strong>Topic</strong></div></td>
    <td width="344" bgcolor="#666666"><div align="center"><strong>Description</strong></div></td>
    <td colspan="2" bgcolor="#333333"><div align="center" class="style2">Action</div></td>
  </tr>
  <?php while ($note=mysql_fetch_assoc($get_note)) { ?>
  <tr valign="top">
  	<td height="40" bgcolor="#CCCCCC"><div align="center"><span class="style1"><?php echo "{$note['note_subject']}"; ?></span></div></td>
    <td bgcolor="#CCCCCC"><div align="center"><span class="style1"><?php echo "{$note['note_topic']}"; ?></span></div></td>
    <td bgcolor="#CCCCCC"><div align="justify"><span class="style1"><?php echo "{$note['note_desc']}"; ?></span></div></td>
    <td width="63" bgcolor="#333333"><div align="center"><?php 
			echo "<a href=\"engine/del_note.php?id={$id}&&topic={$note['note_topic']}&&note_id={$note['notes_id']}\">Delete</a>"; ?></div></td>
    <td width="63" bgcolor="#333333"><div align="center"><span class="style1"><?php echo "<a href=\"{$up_folder}{$note['note_location']}\">Download</a>"; ?></span></div>      <span class="style1"></span></td>
  </tr>
  <?php } ?>
</table>

<table width="780" height="24" border="0" align="center">
  <tr>
    <td width="193" height="20"><span class="style1">List result <?php echo $data+1; ?> - 
      <?php 
		if (($num_row < $limit) || (($num_row-$data)<$limit)) { 
			echo $num_row; 
		} else { 
			echo ($data+$limit); 
		} 
	?> 
    </span></td>
    <td width="188"><span class="style1"></span></td>
    <td width="94"><span class="style1"></span></td>
    <td width="287"><div align="right" class="style1">
		<?php if ($previous==1) {
			echo "<a href=\"page.php?id=" .($data-$limit)."\">Previous</a>";
		} else { ?>Previous<?php } ?>
		 | Page <?php echo $current; ?> | 
	<?php if ($next==1) {
			echo "<a href=\"page.php?id=" .($data+$limit)."\">Next</a>";
		} else { ?>Next<?php } ?> </div></td>
  </tr>
</table>
<div align="center"><br>
  <table width="780" border="0">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><div align="center"><a href="note_reg.php">Register New Notes</a></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</div>
<p>&nbsp;</p>
<p><br>
  <br>
  
  <?php require ("footer.php"); ?>
  
</p>
